//
//  FZUploadFile.m
//  Pods
//
//  Created by liuyong on 15/8/6.
//
//
#import "SRUploadQiniuManager.h"


@implementation SRUploadQiniuManager

+(SRUploadQiniuManager*)sharedInstance
{
    static SRUploadQiniuManager* sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(& onceToken,^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

-(id)init
{
    self=[super init];
    if (self) {
        self.uploadManager = [[QNUploadManager alloc] init];
    }
    return self;
}


-(void)uploadFileToQiNiuForPath:(NSString*)filePath key:(NSString*)key uploadToken:(NSString*)token UploadPercent:(UploadPercent)percentBlock responseBlock:(ResponseInfoBlock)responseBlock
{
    QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithProgessHandler:^(NSString *key, float percent) {
        percentBlock(key,percent);
        NSLog(@"==============%f",percent);
    }];
    [self.uploadManager putFile:filePath key:key token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        responseBlock(info,key,resp);
    } option:uploadOption];
}

- (void)uploadFileToQiNiuForPath:(NSString*)filePath key:(NSString*)key uploadToken:(NSString*)token UploadPercent:(UploadPercent)percentBlock cancelBlock:(CancelBlock)cancelBlock responseBlock:(ResponseInfoBlock)responseBlock {
    QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
        percentBlock(key, percent);
        NSLog(@"==========%f", percent);
    } params:nil checkCrc:NO cancellationSignal:cancelBlock];
    [self.uploadManager putFile:filePath key:key token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        responseBlock(info,key,resp);
    } option:uploadOption];
}

-(void)uploadTalkingFileToQiNiuForPath:(NSString*)filePath UploadPercent:(UploadPercent)percentBlock responseBlock:(ResponseInfoBlock)responseBlock
{
    NSString* keyFileName  = [filePath stringByDeletingPathExtension];
    NSString* keyName = [keyFileName lastPathComponent];
    [self uploadFileToQiNiuForPath:filePath key:keyName uploadToken:[SRLoginUser uploadToken] UploadPercent:percentBlock responseBlock:responseBlock];
}




@end
